//
//  HelpDetailViewController.m
//  DaDaBao
//
//  Created by admin on 15/8/21.
//  Copyright (c) 2015年 User. All rights reserved.
//

#import "HelpDetailViewController.h"

@interface HelpDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *helpTable;
@property(nonatomic,strong)NSMutableArray *dataArr;
@property(nonatomic,assign)float cellHeight;
@end

@implementation HelpDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    
    if ([self.detailTitle isEqualToString:@"关于大大宝"])
    {
        [self.dataArr addObject:@"大大宝是互联网金融下的必然产物，采用特有的P2B（个人对企业）模式，为平台用户提供安全、可靠、高收益的投资信息，是员工福利平台，小额资产保值增值最新通道。我们的愿景就是让那些零花钱通过大大宝的平台体现增值的机会，享受到在线理财的快乐。"];
    }
    if ([self.detailTitle isEqualToString:@"关于充值和提现"])
    {
        [self.dataArr addObject:@"关于充值\n1、登录后进入“我的”界面，点击“充值”按钮\n2、进入“充值”页面后，输入充值金额，选择支付方式进行充值"];
        [self.dataArr addObject:@"关于提现\n1、登录后进入“我的”界面，点击“提现”按钮\n2、依照提示信息填写相关信息\n3、发送验证码至已绑定的手机，接收后输入正确验证码即提现成功"];
    }
    if ([self.detailTitle isEqualToString:@"如何购买"])
    {
        [self.dataArr addObject:@"1、点击“主页”或“项目”按钮后，点击“查看详情”进入详情页面\n2、点击详情页面下方的“立即投资”按钮按提示完成投资\n3、您可以选择使用账户余额进行投资，也可以在完成充值后进行投资"];
        [self.dataArr addObject:@"注：投资前请确认已完成安全设置"];

    }
    if ([self.detailTitle isEqualToString:@"理财学堂"])
    {
        [self.dataArr addObject:@"投资理财是指投资者通过合理安排资金，运用诸如储蓄、银行理财产品、债券、基金、股票、期货、商品现货、外汇、房地产、保险、黄金、P2P等投资理财工具对个人、家庭和企事业单位资产进行管理和分配，达到保值增值的目的，从而加速资产的增长。"];
    }
    if (!_cellHeight) {
        _cellHeight = 44.0f;
    }
    [self createUI];
    
}
-(void)createUI
{
    //    自定义navgationBar
    TopView *topView = [[TopView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_HEIGHT, 64.0f)];
    topView.backgroundColor = [UIColor hexStringToColor:COLOR_VALUE];
    [topView setTitile:@"帮助中心"];
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0.0f, 20.0f, 64.0f, 44.0f)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(buttonBackTapped:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:backBtn];
    
    [self.view addSubview:topView];
    
    if (!_helpTable) {
        if (!_helpTable) {
            _helpTable = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, topView.frame.origin.y+topView.frame.size.height, SCREEN_WIDTH, SCREEN_HEIGHT - 64.0f) style:UITableViewStylePlain];
            _helpTable.backgroundColor = [UIColor whiteColor];
            _helpTable.separatorColor = UITableViewCellSelectionStyleNone;
            _helpTable.delegate = self;
            _helpTable.dataSource = self;
            _helpTable.sectionHeaderHeight = 50.0f;
            _helpTable.separatorStyle = UITableViewCellSelectionStyleNone;
            [self.view addSubview:_helpTable];
        }
    }
    
    

}
#pragma mark--UITableViewDelegate&DataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        UILabel *sepLab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 0.5f)];
        sepLab.backgroundColor = [UIColor grayColor];
        [cell addSubview:sepLab];
        
        
        UILabel *textLab = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.0f, SCREEN_WIDTH-20.0f, 20.0f)];
        textLab.font = [UIFont systemFontOfSize:17.0f];
        textLab.tag = 1000;
        textLab.numberOfLines = 0;
        [cell addSubview:textLab];
    }
    
    float height = [UILabel height:self.dataArr[indexPath.row] widthOfFatherView:SCREEN_WIDTH-20.0f textFont:[UIFont systemFontOfSize:17.0f]]+0.1f;
    UILabel *textLab = (UILabel *)[cell viewWithTag:1000];
    textLab.text = self.dataArr[indexPath.row];
    textLab.frame = CGRectMake(10.0f, 10.0f, SCREEN_WIDTH-20.0f, height);
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    float height = [UILabel height:self.dataArr[indexPath.row] widthOfFatherView:SCREEN_WIDTH-20.0f textFont:[UIFont systemFontOfSize:17.0f]]+0.1f;
    _cellHeight = height+20.0f;

    return _cellHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 50.0f)];
    headerView.backgroundColor = [UIColor whiteColor];
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.0f, SCREEN_WIDTH-20.0f, 30.0f)];
    titleLab.text = self.detailTitle;
    titleLab.font = [UIFont systemFontOfSize:20.0f];
    [headerView addSubview:titleLab];
    

        return headerView;
    
    
}

#pragma mark-返回上一页
-(void)buttonBackTapped:(id)sender
{
    [self.navigationController popViewControllerAnimated:TRUE];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
